Skip to content

屏幕区域实例分割 - YoloSegment

函数简介

截取屏幕区域做实例分割。

接口名称

YoloSegment

DLL 调用

long YoloSegment(long ola, int x1, int y1, int x2, int y2, long modelHandle, double confidence, double iou);

参数说明

参数名类型说明
ola长整数型OLAPlug 对象指针,由 CreateCOLAPlugInterFace 生成。
x1整数型屏幕区域左上角 x(绝对坐标),须 x2>x1
y1整数型屏幕区域左上角 y
x2整数型屏幕区域右下角 x
y2整数型屏幕区域右下角 y
modelHandle长整数型模型句柄,任务类型须与接口一致(Detect/Classify/…)
confidence双精度置信度阈值 0~1:Score 低于此值的候选在 NMS 前丢弃;越大误检越少、漏检越多,常用 0.25~0.5
iou双精度NMS 的 IoU 阈值 0~1:两框重叠度(IoU)超过此值则抑制低分框以去重;越小框越少,常用 0.45~0.7

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
// 加载加密 YOLO 模型包
long modelHandle = ola.YoloLoadModel("models/yolov8n.olam", "your_password", 0);
if (modelHandle == 0) {
    // 模型加载失败,请检查路径与密码
}
// 绑定窗口后截取全屏/客户区做 segment 推理,坐标 0,0,0,0 表示整个客户区
auto result = ola.YoloSegment(0, 0, 1920, 1080, modelHandle, 0.45, 0.5);
if (result.Success) {
    // result.RegionCount 为检测框数量,result.Regions 含坐标与类别
    // 完整 JSON 字段见 YOLO 推理结果说明文档
}
// 失败时可查看 result.Error
csharp
using OLAPlug;

var ola = new OLAPlugServer();
// 加载加密 YOLO 模型包
long modelHandle = ola.YoloLoadModel("models/yolov8n.olam", "your_password", 0);
if (modelHandle == 0)
{
    // 模型加载失败,请检查路径与密码
}
// 绑定窗口后截取全屏/客户区做 segment 推理,坐标 0,0,0,0 表示整个客户区
var result = ola.YoloSegment(0, 0, 1920, 1080, modelHandle, 0.45, 0.5);
if (result.Success)
{
    // result.RegionCount 为检测框数量,result.Regions 含坐标与类别
    // 完整 JSON 字段见 YOLO 推理结果说明文档
}
// 失败时可查看 result.Error
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
# 加载加密 YOLO 模型包
modelHandle = ola.YoloLoadModel("models/yolov8n.olam", "your_password", 0)
if modelHandle == 0:
    # 模型加载失败,请检查路径与密码
    pass
# 绑定窗口后截取全屏/客户区做 segment 推理,坐标 0,0,0,0 表示整个客户区
result = ola.YoloSegment(0, 0, 1920, 1080, modelHandle, 0.45, 0.5)
if result.Success:
    # result.RegionCount 为检测框数量,result.Regions 含坐标与类别
    # 完整 JSON 字段见 YOLO 推理结果说明文档
    pass
# 失败时可查看 result.Error
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
// 加载加密 YOLO 模型包
long modelHandle = ola.YoloLoadModel("models/yolov8n.olam", "your_password", 0);
if (modelHandle == 0) {
    // 模型加载失败,请检查路径与密码
}
// 绑定窗口后截取全屏/客户区做 segment 推理,坐标 0,0,0,0 表示整个客户区
var result = ola.YoloSegment(0, 0, 1920, 1080, modelHandle, 0.45, 0.5);
if (result.Success) {
    // result.RegionCount 为检测框数量,result.Regions 含坐标与类别
    // 完整 JSON 字段见 YOLO 推理结果说明文档
}
// 失败时可查看 result.Error
cpp
var ola = com("OlaPlug.OlaSoft")
// 加载加密 YOLO 模型包
var modelHandle = ola.YoloLoadModel("models/yolov8n.olam", "your_password", 0)
if (modelHandle == 0) {
    // 模型加载失败,请检查路径与密码
}
// 绑定窗口后截取全屏/客户区做 segment 推理,坐标 0,0,0,0 表示整个客户区
var result = ola.YoloSegment(0, 0, 1920, 1080, modelHandle, 0.45, 0.5)
if (result.Success) {
    // result.RegionCount 为检测框数量,result.Regions 含坐标与类别
    // 完整 JSON 字段见 YOLO 推理结果说明文档
}
// 失败时可查看 result.Error
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
' 加载加密 YOLO 模型包
modelHandle = ola.YoloLoadModel("models/yolov8n.olam", "your_password", 0)
If modelHandle = 0 Then
    ' 模型加载失败,请检查路径与密码
End If
' 绑定窗口后截取全屏/客户区做 segment 推理,坐标 0,0,0,0 表示整个客户区
result = ola.YoloSegment(0, 0, 1920, 1080, modelHandle, 0.45, 0.5)
If result.Success Then
    ' result.RegionCount 为检测框数量,result.Regions 含坐标与类别
    ' 完整 JSON 字段见 YOLO 推理结果说明文档
End If
' 失败时可查看 result.Error
text
.局部变量 ola, OLAPlug
ola.创建 ()
' 加载加密 YOLO 模型包
modelHandle = ola.YoloLoadModel(“models/yolov8n.olam“, “your_password“, 0)
.如果真 (modelHandle = 0)
    ' 模型加载失败,请检查路径与密码
.如果真结束
' 绑定窗口后截取全屏/客户区做 segment 推理,坐标 0,0,0,0 表示整个客户区
result = ola.YoloSegment(0, 0, 1920, 1080, modelHandle, 0.45, 0.5)
.如果真 (result.Success)
    ' result.RegionCount 为检测框数量,result.Regions 含坐标与类别
    ' 完整 JSON 字段见 YOLO 推理结果说明文档
.如果真结束
' 失败时可查看 result.Error
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
// 加载加密 YOLO 模型包
var modelHandle = ola.YoloLoadModel("models/yolov8n.olam", "your_password", 0);
if (modelHandle == 0) {
    // 模型加载失败,请检查路径与密码
}
// 绑定窗口后截取全屏/客户区做 segment 推理,坐标 0,0,0,0 表示整个客户区
var result = ola.YoloSegment(0, 0, 1920, 1080, modelHandle, 0.45, 0.5);
if (result.Success) {
    // result.RegionCount 为检测框数量,result.Regions 含坐标与类别
    // 完整 JSON 字段见 YOLO 推理结果说明文档
}
// 失败时可查看 result.Error
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
// 加载加密 YOLO 模型包
长整数 modelHandle = ola.YoloLoadModel("models/yolov8n.olam", "your_password", 0)
if (modelHandle == 0) {
    // 模型加载失败,请检查路径与密码
}
// 绑定窗口后截取全屏/客户区做 segment 推理,坐标 0,0,0,0 表示整个客户区
自动 result = ola.YoloSegment(0, 0, 1920, 1080, modelHandle, 0.45, 0.5)
if (result.Success) {
    // result.RegionCount 为检测框数量,result.Regions 含坐标与类别
    // 完整 JSON 字段见 YOLO 推理结果说明文档
}
// 失败时可查看 result.Error
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
// 加载加密 YOLO 模型包
long modelHandle = ola.YoloLoadModel("models/yolov8n.olam", "your_password", 0);
if (modelHandle == 0) {
    // 模型加载失败,请检查路径与密码
}
// 绑定窗口后截取全屏/客户区做 segment 推理,坐标 0,0,0,0 表示整个客户区
auto result = ola.YoloSegment(0, 0, 1920, 1080, modelHandle, 0.45, 0.5);
if (result.Success) {
    // result.RegionCount 为检测框数量,result.Regions 含坐标与类别
    // 完整 JSON 字段见 YOLO 推理结果说明文档
}
// 失败时可查看 result.Error

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
// 加载加密 YOLO 模型包
long modelHandle = YoloLoadModel(instance, "models/yolov8n.olam", "your_password", 0);
if (modelHandle == 0) {
    // 模型加载失败,请检查路径与密码
}
long resultJsonPtr = YoloSegment(instance, 0, 0, 1920, 1080, modelHandle, 0.45, 0.5);
if (resultJsonPtr != 0) {
    char resultJson[512] = {0};
    GetStringFromPtr(resultJsonPtr, resultJson, sizeof(resultJson));
    FreeStringPtr(resultJsonPtr);
}
csharp
using System.Runtime.InteropServices;
using System.Text;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringFromPtr(long ptr, StringBuilder lpString, int size);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int FreeStringPtr(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringSize(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();

long instance = CreateCOLAPlugInterFace();
// 加载加密 YOLO 模型包
long modelHandle = YoloLoadModel(instance, "models/yolov8n.olam", "your_password", 0);
if (modelHandle == 0)
{
    // 模型加载失败,请检查路径与密码
}
long resultJsonPtr = YoloSegment(instance, 0, 0, 1920, 1080, modelHandle, 0.45, 0.5);
if (resultJsonPtr != 0) {
    StringBuilder resultJson = new StringBuilder(GetStringSize(resultJsonPtr) + 1);
    GetStringFromPtr(resultJsonPtr, resultJson, resultJson.Capacity);
    FreeStringPtr(resultJsonPtr);
    string resultJsonStr = resultJson.ToString();
}
python
from ctypes import CDLL, c_int, c_int64, create_string_buffer

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
# 加载加密 YOLO 模型包
modelHandle = YoloLoadModel(instance, "models/yolov8n.olam", "your_password", 0)
if modelHandle == 0:
    # 模型加载失败,请检查路径与密码
    pass
resultJsonPtr = YoloSegment(instance, 0, 0, 1920, 1080, modelHandle, 0.45, 0.5)
if resultJsonPtr:
    buf = create_string_buffer(512)
    ola.GetStringFromPtr(resultJsonPtr, buf, 512)
    ola.FreeStringPtr(resultJsonPtr)
    resultJson = buf.value.decode("utf-8")

返回值

长整数型:PascalCase JSON 推理结果字符串指针;失败时 Success 为 false。

注意事项

  • 需要插件已开通 YOLO 模块权限(Reg、Login的FeatureList中包含YOLO特性)。
  • 须为 Segment 模型;Region 含 MaskVertices 轮廓。
  • 推理入参(confidence、iou、topK、classes 等)详解见 推理输入参数说明
  • 推理结果 JSON 字段说明见 推理结果JSON说明
  • 返回的 JSON 字符串须调用 FreeStringPtr 释放。

本接口关键参数

参数作用摘要
confidence实例框置信度阈值
iou实例框 NMS 的 IoU 阈值

另输出 MaskVertices 掩码轮廓。详见 推理输入参数说明